package com.liouxb.starter.custom.config;

import com.liouxb.starter.custom.service.MyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 自动配置类并注入bean
 *
 * @author liouwb
 */
@Configuration
@ConditionalOnWebApplication // 生效条件，只有web应用生效
@EnableConfigurationProperties(CustomProperties.class)
public class MyServiceAutoConfiguration {
    @Autowired
    CustomProperties customProperties;

    @Bean
    public MyService myService() {
        MyService service = new MyService();
        service.setCustomProperties(customProperties);

        return service;
    }

}
